#define _CRT_SECURE_NO_WARNINGS 1


#include<set>
#include<vector>
#include<iostream>

using namespace std;

int main()
{
    int n = 0, m = 0;
    cin >> n >> m;
    vector<int> v1(n), v2(m);
    for (int i = 0; i < n; i++)
    {
        cin >> v1[i];
    }
    for (int i = 0; i < m; i++)
    {
        cin >> v2[i];
    }

    set<int> tree;
    int begin1 = 0, end1 = v1.size() - 1;
    int begin2 = 0, end2 = v2.size() - 1;
    int index = 0;
    while (begin1 <= end1 && begin2 <= end2)
    {
        if (v1[begin1] < v2[begin2])
        {
            tree.insert(v1[begin1++]);
        }
        else
        {
            tree.insert(v2[begin2++]);
        }
    }
    while (begin1 <= end1)
    {
        tree.insert(v1[begin1++]);
    }
    while (begin2 <= end2)
    {
        tree.insert(v2[begin2++]);
    }
    for (auto& e : tree)
    {
        cout << e << ' ';
    }
    cout << endl;

    return 0;
}